<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$worker = pdo_get('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
if(empty($worker)){
	exi('您不是'.$this->shifutitle.'！','error','/apply/');
}
$return['isopenvoice']=$this->session('isopenvoice')?1:0;
if($_RQ['op']=='main'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$return['get_money']=pdo_getsum('jy_wxshifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$worker['id']),'get_money');
	$return['lastget_money']=pdo_getsum('jy_wxshifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$worker['id'],'status'=>0),'get_money');
	$return['yesget_money']=pdo_getsum('jy_wxshifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$worker['id'],'status'=>0,'createtime <'=>$cashtime),'get_money');
	$worker['today_money']=pdo_getsum('jy_wxshifu_sendlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$_SESSION['uid'],'status >'=>2,'createtime >'=>$daytime),'fee');
	$worker['today_num']=pdo_count('jy_wxshifu_sendlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$_SESSION['uid'],'status >'=>2,'createtime >'=>$daytime));
	$worker['all_money']=pdo_getsum('jy_wxshifu_sendlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$_SESSION['uid'],'status >'=>2),'fee');
	$worker['all_num']=pdo_count('jy_wxshifu_sendlog',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$_SESSION['uid'],'status >'=>2));
	$worker['viptime']=date('Y-m-d',$worker['viptime']);
	set_html('title',$this->shifutitle.'中心');
	if($_SESSION['wxapp_id']){
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新服务任务通知','jy_wxshifu');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$return['tmplIds']=$tmplIds;
	}
	$worker['url']=custom_url('jy_wxshifu/sao//fromuser='.$_SESSION['uid'],true);
	if($_SESSION['wxapp_id']){
		$image='oss/'.$_SESSION['uniacid'].'/images/jy_wxshifu/wxappid'.$_SESSION['wxapp_id'].'_'.$_SESSION['uid'].'.jpg';
		$isadd=cfc('files')->source_check($image);
		if(!$isadd){
			$url='/jy_wxshifu/sao/index?fromuser='.$_SESSION['uid'];
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
			if($_SESSION['fromh5wxapp']){
				$url='jy_wxshifu/sao//fromuser='.$_SESSION['uid'];
				$url='/pages/index/index?url='.urlencode($url);
			}
			$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
			$path='oss/'.$_SESSION['uniacid'].'/images/jy_wxshifu';
			if(!file_exists(ROOT_AT.$path)){
				mkdir(ROOT_AT.$path,0700, true);
			}
			cfc('files')->source_save($res,'nochoose','png','二维码',$image,'',$url);
		}
		$return['appcode']=$image;
	}
	$return['worker']=$worker;	
	exi($return);
	
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();	
		$data=array(
				'headimg'=>$postdata['headimg'],
				'title'=>$postdata['title'],
				'address'=>$postdata['address'],
				'mobile'=>$postdata['mobile'],
		);
		$worker_id=pdo_getcolumn('jy_wxshifu_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_wxshifu_member',$data,array('id'=>$worker_id));
			exi('修改成功','','main');		 
		}
	}
	$worker=pdo_get('jy_wxshifu_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
if($_RQ['op']=='setonline'){
	$post=get_postdata();
	$id=$post['id'];
	$online=$post['online'];
	pdo_update('jy_wxshifu_member',array('online'=>$online),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if($online==0){
		exi('成功离线！');	
	}elseif($online==1){
		exi('成功上线！');	
	}elseif($online==2){
		exi('成功忙碌！');	
	}	 
}
if($_RQ['op']=='getnew'){
	$worker = pdo_get('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
	$params=array(
		'status'=>array(0,1),
		'uniacid'=>$_SESSION['uniacid'],
		'shifuid'=>$worker['id'],
	);
	$this->session('isopenvoice',1);
	$order=pdo_get('jy_wxshifu_order',$params);
	if($order['id']){
		exi($order);
	}else{
		unset($params['shifuid']);
		$params['status']=0;
		$order=pdo_get('jy_wxshifu_order',$params);
		if($order['id']){
			exi($order);
		}else{
			exi('none');
		}
	}
}
if($_RQ['op']=='setopenvoice'){
	$isopenvoice=$_RQ['isopenvoice'];
	$isopenvoice=$isopenvoice?1:0;
	$this->session('isopenvoice',$isopenvoice);
	pdo_update('jy_wxshifu_member',array('online'=>$isopenvoice),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi($return);
}
if($_RQ['op']=='dw'){
	$post=get_postdata();
	pdo_update('jy_wxshifu_member',array('latlng'=>ijson_encode($post['latlng']),'uplat_time'=>TIMESTAMP),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi($return);
}
?>